<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Firefox视频调试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background: #f5f5f5;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .video-container {
            position: relative;
            border-radius: 8px;
            overflow: hidden;
            background: #000;
            aspect-ratio: 16/9;
            margin: 20px 0;
        }
        .video-element {
            width: 100%;
            height: 100%;
            object-fit: cover;
            border-radius: 8px;
            background: #000;
            -webkit-transform: scaleX(-1);
            -moz-transform: scaleX(-1);
            transform: scaleX(-1);
            display: block;
        }
        .button {
            background: #6200ee;
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 4px;
            cursor: pointer;
            margin: 5px;
            font-size: 14px;
        }
        .button:hover {
            background: #3700b3;
        }
        .log {
            background: #fafafa;
            border: 1px solid #e0e0e0;
            border-radius: 4px;
            padding: 10px;
            margin-top: 20px;
            font-family: monospace;
            font-size: 12px;
            max-height: 300px;
            overflow-y: auto;
        }
        .status {
            padding: 10px;
            margin: 10px 0;
            border-radius: 4px;
            border-left: 4px solid #4caf50;
        }
        .error {
            background: #ffebee;
            border-left-color: #f44336;
        }
        .warning {
            background: #fff3e0;
            border-left-color: #ff9800;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Firefox视频调试</h1>
        <p>专门用于调试Firefox中的视频显示问题</p>
        
        <div>
            <button class="button" onclick="testVideo()">测试视频</button>
            <button class="button" onclick="debugInfo()">调试信息</button>
            <button class="button" onclick="clearLog()">清除日志</button>
        </div>
        
        <div id="status" class="status" style="display: none;"></div>
        
        <div class="video-container">
            <video id="testVideo" class="video-element" autoplay muted playsinline></video>
        </div>
        
        <div id="log" class="log"></div>
    </div>

    <script>
        let currentStream = null;

        function log(message) {
            const logElement = document.getElementById('log');
            const timestamp = new Date().toLocaleTimeString();
            logElement.innerHTML += `[${timestamp}] ${message}\n`;
            logElement.scrollTop = logElement.scrollHeight;
            console.log(message);
        }

        function showStatus(message, type = 'success') {
            const statusElement = document.getElementById('status');
            statusElement.innerHTML = message;
            statusElement.className = `status ${type}`;
            statusElement.style.display = 'block';
        }

        async function testVideo() {
            log('开始测试视频...');
            showStatus('正在获取视频流...', 'warning');
            
            try {
                if (currentStream) {
                    currentStream.getTracks().forEach(track => track.stop());
                }

                const stream = await navigator.mediaDevices.getUserMedia({ 
                    video: {
                        width: { ideal: 640 },
                        height: { ideal: 480 },
                        facingMode: 'user'
                    },
                    audio: false
                });
                
                currentStream = stream;
                log(`成功获取视频流: ${stream.id}`);
                log(`视频轨道数量: ${stream.getVideoTracks().length}`);
                
                const video = document.getElementById('testVideo');
                video.srcObject = stream;
                
                log('已设置视频流到元素');
                
                // 尝试播放
                const playPromise = video.play();
                if (playPromise !== undefined) {
                    playPromise
                        .then(() => {
                            log('视频播放成功');
                            showStatus('视频播放成功！', 'success');
                        })
                        .catch(e => {
                            log(`视频播放失败: ${e.message}`);
                            showStatus(`视频播放失败: ${e.message}`, 'error');
                        });
                }
                
            } catch (error) {
                log(`获取视频流失败: ${error.name} - ${error.message}`);
                showStatus(`获取视频流失败: ${error.message}`, 'error');
            }
        }

        function debugInfo() {
            log('=== 调试信息 ===');
            log(`浏览器: ${navigator.userAgent}`);
            log(`支持getUserMedia: ${navigator.mediaDevices && navigator.mediaDevices.getUserMedia ? '是' : '否'}`);
            
            const video = document.getElementById('testVideo');
            log(`视频元素: ${video ? '存在' : '不存在'}`);
            if (video) {
                log(`视频元素属性:`);
                log(`  - id: ${video.id}`);
                log(`  - className: ${video.className}`);
                log(`  - srcObject: ${video.srcObject ? '已设置' : '未设置'}`);
                log(`  - readyState: ${video.readyState}`);
                log(`  - paused: ${video.paused}`);
                log(`  - currentTime: ${video.currentTime}`);
                log(`  - videoWidth: ${video.videoWidth}`);
                log(`  - videoHeight: ${video.videoHeight}`);
            }
            
            if (currentStream) {
                log(`当前流信息:`);
                log(`  - id: ${currentStream.id}`);
                log(`  - 轨道数量: ${currentStream.getTracks().length}`);
                log(`  - 视频轨道: ${currentStream.getVideoTracks().length}`);
            }
        }

        function clearLog() {
            document.getElementById('log').innerHTML = '';
        }

        window.addEventListener('load', function() {
            log('页面已加载');
            log(`浏览器信息: ${navigator.userAgent}`);
            
            const isFirefox = navigator.userAgent.toLowerCase().includes('firefox');
            if (isFirefox) {
                log('检测到Firefox浏览器');
            }
        });

        window.addEventListener('beforeunload', function() {
            if (currentStream) {
                currentStream.getTracks().forEach(track => track.stop());
                log('已清理媒体流资源');
            }
        });
    </script>
</body>
</html> 